package com.example.dairenkun.neufoodshop.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dairenkun.neufoodshop.R;
import com.example.dairenkun.neufoodshop.activity.FoodDetailActivity;
import com.example.dairenkun.neufoodshop.bean.Collection;
import com.example.dairenkun.neufoodshop.bean.doCollect;
import com.example.dairenkun.neufoodshop.model.FoodModel;
import com.squareup.picasso.Picasso;

import java.util.List;

;import retrofit2.Call;
import retrofit2.Callback;

/**
 * Created by Administrator on 2017/3/6.
 */

public class CollectFoodAdapter extends RecyclerView.Adapter<ViewHolder> {
    int userid;
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public CollectFoodAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.inflate(R.layout.cardview_collectfood, parent, false);
        return new ViewHolder(v);


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       final Collection entity=(Collection) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        if (entity.getFoodname().equals(""))
        { viewHolder.food_name.setText("无"); }
        else{
            viewHolder.food_name.setText(entity.getFoodname()+"");
        }

       viewHolder.food_price.setText(entity.getPrice()+"元");
        if (!"".equals(entity.getPic()))
        Picasso.with(mContext).load(entity.getPic()).into(viewHolder.food_image);
        //quxiao
        viewHolder.btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
        //点击进入详情
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext,FoodDetailActivity.class);
                intent.putExtra("food_id",entity.getFood_id()+"");
                mContext.startActivity(intent);

            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView food_name;
        ImageView food_image;
        TextView food_price;
        Button btn_cancel;



        public ViewHolder(View itemView) {
            super(itemView);
            food_name = (TextView) itemView.findViewById(R.id.Collectfood_name);
            food_image = (ImageView) itemView.findViewById(R.id.Collectfood_image);
            food_price = (TextView) itemView.findViewById(R.id.Collectfood_money);
            btn_cancel=(Button)itemView.findViewById(R.id.btn_Collectfood_cancel);


        }

    }

    private void getUser(){
        //context=getActivity();
        SharedPreferences sp = mContext.getSharedPreferences("UserInfo", mContext.MODE_PRIVATE);
        userid = Integer.valueOf(sp.getString("user_id", null));
        //Toast.makeText(context,userid,Toast.LENGTH_SHORT).show();

    }
}
